<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\app\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\AdminMenuModel;
use think\Validate;
use api\wxapp\model\User;
use api\wxapp\model\Shop;
use api\wxapp\model\Order;
class OrderController extends AdminBaseController
{
    private $shop_id = 0;
    public function initialize()
    {
        parent::initialize();
        $sessionAdminId = session('ADMIN_ID');
        if($sessionAdminId !== 1){
            //说明是店铺登陆
            $id = Shop::where('admin_id',$sessionAdminId)->value('id');
            $this->shop_id = $id;
        }
    }
    //点赞
    public function index(Order $order)
    {
        $where = array();
        if($this->shop_id){
            $where[] = ['t1.shop_id','eq',$this->shop_id];
        }
        $params = $this->param();
        if(isset($params['name']) && $params['name']){
            $where[] = ['t3.name','like','%'.$params['name'].'%'];
        }
        if(isset($params['phone']) && $params['phone']){
            $where[] = ['t2.phone','like','%'.$params['phone'].'%'];
        }
        if(isset($params['status']) && $params['status']){
            $where[] = ['t1.status','eq',$params['status']];
            $this->assign('status',$params['status']);
        }
        if(isset($params['pay_type']) && $params['pay_type']){
            $where[] = ['t1.pay_type','eq',$params['pay_type']];
            $this->assign('pay_type',$params['pay_type']);
        }
        $query = Order::alias('t1');
        $query = $order->leftuser($query);
        $query = $order->leftshop($query);
        $query = $order->returnfield($query);
        $query = $order->orderId($query);
        $list = $query->where($where)->paginate(10);
        $this->assign('shop_id',$this->shop_id);
        $this->assign('list',$list);
        $list->appends($params);  //分页条件
        $this->assign('page', $list->render());
        return $this->fetch();
    }
    //订单商品
    public function lst()
    {
        $params = $this->param();
        $list = db::name('app_goods_order_list')->alias('t1')
            ->join('app_shop t2','t2.id = t1.goods_id')
            ->field('t1.*,t2.name')
            ->where('t1.order_id',$params['id'])
            ->paginate(10);
        $this->assign('list',$list);  
        $this->assign('page', $list->render());  
        return $this->fetch();   
    }
}
